/*
 * Scheduler.c
 *
 *  Created on: Mar 8, 2012
 *      Author: 234
 */

#include "Simulator.h"
#include <stdio.h>

void initializeScheduler(Scheduler* s, int t, Process *p[]) {
	s->CurrentProcess = 0; //first call to getNext will return 0
	s->type = t%3; //only 3 types, 0 = round robin, 1 = priority, 2 = lottery.
	s->my_processes[0] = p[0];
	s->my_processes[1] = p[1];
	s->my_processes[2] = p[2];
	s->my_processes[3] = p[3];
}

Process* getNext(Scheduler* s) {
	switch(s->type)
	{
	    case 0:
	    	s->CurrentProcess = (s->CurrentProcess++);
	    	break;
	    case 1:
	    	s->CurrentProcess = (s->CurrentProcess++); //TODO Priority
	    	break;
	    case 2:
	    	s->CurrentProcess = (rand());
	    	break;
	    default :
	    	printf("Invalid Schedule Type");
	    	break;
	}
	return s->my_processes[s->CurrentProcess%4];//Make this return Array[s->CurrentProcess]
}

Process* getCurrent(Scheduler* s) {
	return s->my_processes[s->CurrentProcess%4]; //Make this return Array[s->CurrentProcess]
}
